<template>
  <div>
    <div class="form_wrap">
      <el-form label-width="120px" style="margin-top:10px">
        <!--end 贷款-->
        <div class="wrap clearfix">
          <div class="title">
            贷款信息：
            <div class="button">
              <el-button
                @click="openDiaAj"
                v-if="showChargeBtn && orderStatus == 3"
                >{{ ajTitle }}</el-button
              >
            </div>
          </div>
          <div>
            <div class="li_wrap">
              <el-form-item class="posInput ts" label="买家按揭银行:">
                <el-input v-model="aj.buyLoansBank" :disabled="true"></el-input>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item class="posInput ts" label="按揭金额:">
                <span class="pos left">小写</span>
                <el-input
                  v-model="aj.basicLoansMoney"
                  :disabled="true"
                ></el-input>
                <span class="pos right">（万元）</span>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item class="posInput ts" label="买家按揭期限:">
                <el-input
                  v-model="aj.basicLoansMonths"
                  :disabled="true"
                ></el-input>
                <span class="pos right">（月）</span>
              </el-form-item>
            </div>
            <div class="li_wrap" style="height:37px"></div>
            <div class="li_wrap">
              <el-form-item label="保函时间:">
                <el-date-picker
                  v-model="aj.loanUpTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item class="posInput" label="放款账号:">
                <el-input v-model="aj.accountNum" :disabled="true"></el-input>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item class="posInput" label="开户行:">
                <el-input v-model="aj.accountBank" :disabled="true"></el-input>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item class="posInput" label="开户名:">
                <el-input v-model="aj.accountName" :disabled="true"></el-input>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
    </div>
    <!--弹框-->
    <el-dialog
      title="编辑信息"
      :visible.sync="dialogTableVisible"
      v-if="dialogTableVisible && orderStatus == 3"
    >
      <el-form label-width="150px" v-if="showdis == 0" :model="diaAj">
        <el-row>
          <el-col :span="12">
            <el-form-item class="posInput ts" label="买家按揭银行:">
              <el-input v-model="diaAj.buyLoansBank"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="posInput ts" label="买家按揭金额:">
              <span class="pos left">小写</span>
              <el-input v-model="diaAj.basicLoansMoney"></el-input>
              <span class="pos right">（万元）</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="posInput ts" label="买家按揭期限:">
              <el-input v-model="diaAj.basicLoansMonths"></el-input>
              <span class="pos right">（月）</span>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12" style="height:62px"></el-col> -->
          <el-col :span="12">
            <el-form-item label="出保函时间:">
              <el-date-picker
                v-model="diaAj.loanUpTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
                style="width:310px"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="posInput" label="放款账号:">
              <el-input v-model="diaAj.accountNum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="posInput" label="开户行:">
              <el-input v-model="diaAj.accountBank"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="posInput" label="开户名:">
              <el-input v-model="diaAj.accountName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitAj">确 定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  getAucMort,
  getProductUrl,
  putAucMort
} from "../../../src/assets/js/api";
import { checkPermiss } from "../../assets/js/utlis";
import { GMTToStr } from "../../assets/js/utlis";
export default {
  name: "LoanInfor",
  props: ["orderNumber"],
  data() {
    return {
      dialogTableVisible: false,
      //按揭
      aj: {},
      diaAj: {},
      ajTitle: "修改",
      showdis: null,
      golbalPermissions: [],
      ProductUrl: "",
      orderStatus: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      }
    };
  },
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.status = eval(this.$route.query.status);
    if (!this.status) {
      this.getUpForm(this.orderNumber);
    }
    this.findProductUrl(this.orderNumber);
  },
  computed: {
    //财务信息添加按钮
    showChargeBtn: function() {
      return checkPermiss("business:auction:mortgage", this.golbalPermissions);
    }
  },
  watch: {
    "aj.buyLoansBank": {
      handler(newName) {
        if (!newName) {
          this.ajTitle = "添加数据";
        } else {
          this.ajTitle = "修改";
        }
      }
    }
  },
  methods: {
    //根据订单查询路由path路径
    findProductUrl(orderNumber) {
      getProductUrl({
        orderNumber: orderNumber
      }).then(res => {
        this.ProductUrl = res.data.productUrl;
        this.orderStatus = res.data.orderStatus;
      });
    },
    //根据订单号查询当前信息
    getUpForm(orderNumber) {
      getAucMort(orderNumber).then(res => {
        let data = res.data;
        //按揭
        this.$set(this.aj, "buyLoansBank", data.buyLoansBank);
        this.$set(this.aj, "basicLoansMoney", data.basicLoansMoney);
        this.$set(this.aj, "basicLoansMonths", data.basicLoansMonths);
        this.$set(this.aj, "loanUpTime", data.loanUpTime);
        this.$set(this.aj, "accountNum", data.accountNum);
        this.$set(this.aj, "accountBank", data.accountBank);
        this.$set(this.aj, "accountName", data.accountName);
      });
    },
    //按揭
    openDiaAj() {
      this.showdis = 0;
      this.dialogTableVisible = true;
      this.diaAj = JSON.parse(JSON.stringify(this.aj));
    },
    //按揭提价按钮
    submitAj() {
      this.diaAj.orderNumber = this.orderNumber;
      if (this.diaAj.loanUpTime) {
        this.diaAj.loanUpTime = GMTToStr(this.diaAj.loanUpTime);
      }
      putAucMort(this.diaAj).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    }
  }
};
</script>

<style scoped type="less">
.posInput {
  position: relative;
}
.pos {
  position: absolute;
  z-index: 2;
}
.pos.left {
  left: 10px;
}
.pos.right {
  right: 0;
}
.posInput ::v-deep .el-input__inner {
  padding: 0 50px 0 40px;
  text-align: center;
}
.posInput.ts ::v-deep .el-input__inner {
  padding-left: 25px;
}
.toBe {
  line-height: 35px;
}
.form_wrap ::v-deep .el-form-item,
.form_wrap ::v-deep .el-form-item__label,
.form_wrap ::v-deep .el-form-item__content,
.form_wrap ::v-deep .el-input,
.form_wrap ::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
}
.form_wrap ::v-deep .el-form-item {
  margin-bottom: 5px;
}
.form_wrap ::v-deep .el-col {
  line-height: 32px;
}
.form_wrap ::v-deep .el-button {
  padding: 8px 20px;
}
.form_wrap ::v-deep.el-input__icon {
  line-height: 24px;
}
::v-deep .el-form-item__content {
  text-align: left;
}
.el-date-editor.el-input {
  width: auto;
}
.li_wrap {
  width: 25%;
  min-width: 250px;
  float: left;
}
.form_wrap .wrap {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(238, 238, 238, 1);
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 5px;
}
.form_wrap .title {
  text-align: left;
  font-size: 15px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  line-height: 40px;
}
.form_wrap .button {
  float: right;
}
</style>
